package com.forlove.app.qselect.update.presenter;

import android.text.TextUtils;

import com.forlove.app.common.base.mvp.presenter.IBasePresenter;
import com.forlove.app.common.network.ICallBack;
import com.forlove.app.common.utils.ParseHelper;
import com.forlove.app.manager.ServerManager;
import com.forlove.app.qselect.update.entity.UpdateEntity;
import com.forlove.app.qselect.update.service.IUpdateService;
import com.forlove.app.qselect.update.service.impl.UpdateImpl;
import com.forlove.app.qselect.update.view.MainView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by yinzhiqiang on 2017/11/2.
 */

public class UpdataPresenter extends IBasePresenter {
    private MainView mainView;
    private IUpdateService updateService;

    public UpdataPresenter(MainView mainView) {
        this.mainView = mainView;
        updateService = new UpdateImpl();
        setService(updateService);
    }

    public void update(String version) {
        Map map = new HashMap();
        map.put("device_type", "android");

        if (!TextUtils.isEmpty(version)) {
            map.put("app_version", version);
        }
        updateService.loadData(ServerManager.ACTION_UPDATE, map, new ICallBack() {
            @Override
            public void onSuccess(int statusCode, String result) {
                UpdateEntity entity = ParseHelper.getModel(result.toString(), "data", UpdateEntity.class);
                mainView.showDownloadDialog(entity);
            }

            @Override
            public void onFail(int statusCode, String result) {

            }
        });
    }

}
